package com.liujun.spring4.demo.aop.pointcut.staticmethod;

import org.springframework.aop.ClassFilter;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;

import java.lang.reflect.Method;

/**
 * 切面类的代码
 *
 * @author liujun
 * @version 0.0.1
 * @date 2018/09/22
 */
public class GreetingAdvisor extends StaticMethodMatcherPointcutAdvisor {

  @Override
  public boolean matches(Method method, Class<?> targetClass) {
    // 切点 方法匹配规则，方法名是否为greetTo
    return "greetTo".equals(method.getName());
  }

  @Override
  public ClassFilter getClassFilter() {
    // 切点 类匹配规则，为Waiter的类或者子类
    return new ClassFilter() {
      @Override
      public boolean matches(Class<?> clazz) {
        return Waiter.class.isAssignableFrom(clazz);
      }
    };
  }
}
